package com.chat.service;

import com.chat.Local;
import com.chat.common.ChatMsg;
import com.chat.common.Message;
import com.chat.common.MessageType;
import com.chat.view.MainWindowView;
import javafx.application.Platform;

import java.text.SimpleDateFormat;
import java.util.Date;

/*
私聊
 */
public class PrivateChat {
      public void privatechattext(String senderid,String sendernickname,String receive,String content){//文字私聊
            Message msg=new Message();
            ChatMsg cm=new ChatMsg();
            Date date = new Date();
            SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
            cm.setContent(content);
            cm.setSenderid(senderid);
            cm.setSendernickname(sendernickname);
            cm.setReceive(receive);
            cm.setTime(dateFormat.format(date));
            msg.setData(cm);
            msg.setMesType(MessageType.MESSAGE_PRIVATE_CHAT_TEXT);
            ClientConnectServerThread clientConnectServerThread=ManageClientConnectServerThread.getClientConnectServerThread(Local.user.getUsername());
            clientConnectServerThread.send(msg);
            Platform.runLater(()-> {
                  ((javafx.scene.control.TextArea) MainWindowView.$("inputbox")).setText("");
            });
      }
      public void privatechatimage(String senderid,String sendernickname,String receive,String filename,byte[] file){//图片私聊
                  Message msg=new Message();
                  Date date = new Date();
                  SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
                  msg.setMesType(MessageType.MESSAGE_PRIVATE_CHAT_IMAGE);
                  ChatMsg cm=new ChatMsg();
                  cm.setType("2");
                  cm.setTime(dateFormat.format(date));
                  cm.setSenderid(senderid);
                  cm.setSendernickname(sendernickname);
                  cm.setReceive(receive);
                  cm.setFilename(filename);
                  cm.setFile(file);
                  msg.setData(cm);
                  ClientConnectServerThread clientConnectServerThread=ManageClientConnectServerThread.getClientConnectServerThread(Local.user.getUsername());
                  clientConnectServerThread.send(msg);
      }
      public void privatechatfile(String senderid,String sendernickanme,String receive,String address,String filename,String time){//文件私聊
                Message msg=new Message();
                msg.setMesType(MessageType.MESSAGE_PRIVATE_CHAT_FILE);
                ChatMsg cm=new ChatMsg();
                cm.setTime(time);
                cm.setSenderid(senderid);
                cm.setSendernickname(sendernickanme);
                cm.setReceive(receive);
                cm.setAddress(address);
                cm.setFilename(filename);
                cm.setType("3");
                msg.setData(cm);
          ClientConnectServerThread clientConnectServerThread=ManageClientConnectServerThread.getClientConnectServerThread(Local.user.getUsername());
          clientConnectServerThread.send(msg);
      }
}
